﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using EmoneyWeiXinCommon;
using EmoneyWeiXinEntity;
using System.Data;

namespace EmoneyWeiXinDAL
{
    public class TJ_Business_USerScanDAL
    {
        //根据条件获取统计数据
        public List<TJ_Business_USerScanEntity> GetUSerScanListByCondition(int weixinId, string tradeType, DateTime tStartTime, DateTime tEndtime)
        {

            string sql = "SELECT top 30 * FROM TJ_Business_USerScan with(nolock) ";
            string whereTextt = "where wexinid=@wexinid AND TradeType=@TradeType AND (TradeTime>=@startTime AND TradeTime<=@endTime)";
            sql = sql + whereTextt;
            List<SqlParameter> paraLst = new List<SqlParameter>();
            return SQLHelper.GetDataByColumnsLst<TJ_Business_USerScanEntity>(Config.EmoneyWeiXin, sql, paraLst.ToArray());
        }
        //分页获取统计数据
        public List<TJ_Business_USerScanEntity> GetUSerScanListForPage(int pageSize, int pageIndex, string whereText, out int totalPage)
        {
            PageHelper pgHelper = new PageHelper("TJ_Business_USerScan", "id");
            pgHelper.CurrentPage = pageIndex;
            pgHelper.PageSize = pageSize;
            pgHelper.WhereText = whereText;
            DataTable dt = pgHelper.GetData();
            totalPage = pgHelper.TotalRecord;
            return SQLHelper.DataConvert<TJ_Business_USerScanEntity>(dt);

        }

        public void GetSumDataByTimeArea(out int subSum, out int unSubSum, string whereText)
        {
            string sql = " select ISNULL( SUM(SubscribeCount),0) sCount,ISNULL( SUM(UNSubscribeCount),0) unScount from TJ_Business_USerScan with(nolock)";
            sql = sql +" where " +whereText;
            //sql += " where TradeType='D' AND wexinid=@wexinid  AND (TradeTime>=@startTime AND TradeTime<=@endTime)";
            //SqlParameter[] paras = { new SqlParameter("@wexinid", weixinId), new SqlParameter("@startTime", startTime), new SqlParameter("@endTime", endTime) };
            DataTable dt = SQLHelper.ExecuteGetTable(Config.EmoneyWeiXin, CommandType.Text, sql);
            subSum = Convert.ToInt32(dt.Rows[0]["sCount"]);
            unSubSum = Convert.ToInt32(dt.Rows[0]["unScount"]);
        }
    }
}
